package org.cxn.tools.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by chenxiangning on 2015/8/9.
 */
public class Main {
    private static final Logger logger = LoggerFactory.getLogger(Main.class);

    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = ThreadPoolManager.instance().buildFixedThreadPool(20);
        final Random r = new Random();

        for (int i = 0; i < 5; i++) {
            threadPoolExecutor.execute(new Runnable() {
                public void run() {
                    try {
                        int ri = r.nextInt(600);
                        while (true) {
                            Thread.sleep(ri);
                            logger.info("test    " + Thread.currentThread().getName());
                        }
                    } catch (InterruptedException e) {

                    }
                }
            });
            logger.info("qidong:#########################  " + i);
        }

        threadPoolExecutor.shutdown();
    }
}
